package com.fyzk.activity.lottery.shuzicai;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.fyzk.utils.L;

public class PopRightClick extends PopupWindow {

	private final String TAG = this.getClass().getSimpleName();

	private Context context;

	private ListView listView;
	private View view;
	private String[] items ;
	private int[] imgs;

//	@Deprecated
//	public PopRightClick(Context context, View view,int width, int height, String[] titles) {
//		super(width, height);
//		this.context = context;
//		this.items = titles;
//		this.view = view;
//		this.setBackgroundDrawable(new BitmapDrawable());
//		this.setOutsideTouchable(true);
//		// 设置此参数获得焦点，否则无法点击
//		this.setFocusable(true);
//		info();
//		this.setContentView(view);
//	}
	public PopRightClick(Context context, View view,int width, int height ,String[] titles, int[] imgs) {
		super(view, width, height);
		this.context = context;
		this.items = titles;
		this.imgs = imgs;
		this.view = view;
		this.setBackgroundDrawable(new BitmapDrawable());
		this.setOutsideTouchable(true);
		// 设置此参数获得焦点，否则无法点击
		this.setFocusable(true);
		info();
		this.setContentView(view);
	}
	
	public PopRightClick(Context context, View view ,String[] titles, int[] imgs) {
		super(view,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		this.context = context;
		this.view = view;
		this.items = titles;
		this.imgs = imgs;
		this.setBackgroundDrawable(new BitmapDrawable());
		this.setOutsideTouchable(true);
		// 设置此参数获得焦点，否则无法点击
		this.setFocusable(true);
		this.setTouchable(true);
		info();
		this.setContentView(view);
	}
	
	@Override
	public void showAsDropDown(View anchor) {
		// TODO Auto-generated method stub
		super.showAsDropDown(anchor);
		L.v(TAG, "showAsDropDown>>>>>");
	}

	private void info() {
		// TODO Auto-generated method stub
		if(null!=items){
			L.v(TAG, "info>>>>>");
			L.v(TAG, "items>>>>>"+items.length);
//			listView = (ListView) view.findViewById(R.id.dj_pop_listview);
//			listView.setAdapter(new PopAdapter());
//			listView.setOnItemClickListener(listener);
		}

	}

	public OnItemClickListener listener;

	public void setOnItemClickListener(OnItemClickListener listener) {
		if(null!=listener){
			this.listener = listener;
			listView.setOnItemClickListener(listener);
		}
	}
	
	class PopAdapter extends BaseAdapter{

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return items.length;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return items[position];
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {

			convertView = LayoutInflater.from(context).inflate(android.R.layout.activity_list_item, null);
			VH holder = new VH();
			
//			holder.iv = (ImageView) convertView.findViewById(R.id.dj_pop_item_iv);
			holder.tv = (TextView) convertView;
			convertView.setTag(holder);
			try {
//				holder.iv.setImageResource(imgs[position]);
				holder.tv.setText(items[position]);
			} catch (Exception e) {
				// TODO: handle exception
			}
			
			return convertView;
		}
		
		class VH {
//			ImageView iv;
			TextView tv;
		}
		
	}


}
